package com.next

class WorkflowUser
{
    Position position
    WorkflowAuthority authority

    Date createdDate = new Date()
    Date modifiedDate = new Date()

    User createBy
    User modifyBy

    static belongsTo = [stage: WorkflowStage]

    static constraints = {
        authority unique: ['stage']
        createBy nullable: true, blank: true
        modifyBy nullable: true, blank: true
        createdDate nullable: true, blank: true
        modifiedDate nullable: true, blank: true
    }

    def springSecurityService

    def beforeInsert()
    {
        def username = springSecurityService?.getPrincipal()?.username
        createBy = User.findByUsername(username)
    }

    def beforeUpdate()
    {
        modifiedDate = new Date()
        def username = springSecurityService?.getPrincipal()?.username
        modifyBy = User.findByUsername(username)
    }
}
